<template>
	<BaseContainer
		class="report-table-wrapper"
		v-loading="loading"
		element-loading-text="加载中..."
		element-loading-background="rgba(255, 255, 255, 0.8)"
	>
		<div class="t-header">
			<div @click="drawer = !drawer" class="article-title">
				<p
					class="text-tip"
					id="no-print"
					v-if="modelData.viewStatus"
					:style="{ opacity: modelData['viewStatus'] == null ? 0 : 1, '--base-text-bg': modelData['viewStatus'] == 1 ? '' : '#dc8844af' }"
				>
					<span class="tip-text-detail" v-if="modelData.viewStatus == 1">详</span>
					<span class="tip-text-new" v-else>新</span>
				</p>
				<span>南京市养老护理岗位工作人员入职奖励申请表</span>
			</div>
		</div>
		<ReportTable :column="dataList" :isDetail="true" :moreNewsModel="moreNewsModel" :baseModel="baseModel" :model="modelData" @change="handleSave">
			<template v-slot:staffPhoto>
				<div style="width: 100px">
					<img style="width: 100px" :src="modelData.staffPhoto" alt="" />
				</div>
			</template>
			<template v-slot:moneyAndYear>
				<el-input v-if="!isDetail" :disabled="isDetail" v-model="modelData.moneyAndYear" @blur="editMoneyAndYear"></el-input>
				<span v-else>{{ modelData.moneyAndYear }}</span>
			</template>
			<template v-slot:applyMoneyAndYear>
				<el-input v-if="!isDetail" :disabled="isDetail" v-model="modelData.applyMoneyAndYear" @blur="editMoneyAndYear"></el-input>
				<span v-else>{{ modelData.applyMoneyAndYear }}</span>
			</template>
			<template v-slot:note>
				<div class="w-100 tr flex-column" style="min-height: 120px; line-height: 60px">
					<div class="p-r-50">
						<p style="padding-right: 6vw">承办人签名： （单位盖章）</p>
						<p style="padding-right: 20vw">年 月 日</p>
					</div>
				</div>
			</template>
      <template v-slot:noteS>
				<div class="w-100 tr flex-column" style="min-height: 120px; line-height: 60px">
					<div class="p-r-50">
						<p style="padding-right: 6vw"> 街（镇）民政部门：（章）</p>
						<p style="padding-right: 3vw">年 月 日</p>
					</div>
				</div>
			</template>
       <template v-slot:noteT>
				<div class="w-100 tr flex-column" style="min-height: 120px; line-height: 60px">
					<div class="p-r-50">
            <p>
              经现场核查：被查人员：<span class="text-underline">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> （姓名），<span class="text-underline">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> （符合/不符合）入职奖励申请条件。
            </p>
						<p style="padding-right: 6vw">第三方机构：（章）</p>
						<p style="padding-right: 3vw">年 月 日</p>
					</div>
				</div>
			</template>
			<template v-slot:note2>
				<div class="w-100 tr flex-column" style="min-height: 120px; line-height: 60px">
					<div class="p-r-50">
						<p style="padding-right: 6vw">区民政部门：（章）</p>
						<p style="padding-right: 3vw">年 月 日</p>
					</div>
				</div>
			</template>
		</ReportTable>
		<OrgArchives ref="orgArchivesEl"></OrgArchives>
		<!-- 从业人员档案 -->
		<aplid-dialog 
		:append-to-body="true" 
		v-model="staffInfoShow" 
		whickComm="detail"
		:customeHeader="detailConfig?.customeHeader"
		:model="modelData"
		title="从业人员档案" 
		width="85%">
		<PractitionerArchives :nowRowData="modelData"></PractitionerArchives>
		</aplid-dialog>
	</BaseContainer>
</template>

<script setup lang="ts">
import ReportTable from './ReportTable/index.vue'
import OrgArchives from './OrgArchives/index.vue'
import apiMod from '@/apiMod'
import { filterEmptyObj } from '@/utils/util'
// import PractitionerArchives from '@/views/datacenter/basicData/practitioner/Archives/index.vue'
import PractitionerArchives from '@/views/instOperate/components/ApplyReport/practitioner/Archives/index.vue'
import bus from '@/utils/eventbus'

const props = defineProps<{
	params?: any
	creditCode?: string | number
	editData?: any
	isDetail?: boolean
	caseId?: string | number
	custome?: boolean
	approvalStatus?: string | number
	otherData?:any
	isPigeonhole?:boolean
}>()

const emit = defineEmits(['save'])
let staffInfoShow = ref(false)
const detailConfig = {
	customeHeader: {
		integrityConfig: {
			baseTableName: 'dp_foundation_practitioners',
			materialTableName: 'dp_foundation_practitioners_material',
			soleValue: 'idCard',
		},
		type: 'CardTwo',
		title: 'staffName',
		avatar: 'staffPhoto',
		tipList: [{ prop: 'phone', type: 'tip-success', label: '联系电话' }],
		tagList: [
			// { prop: 'healthyStateLabel', code: 'HEALTHY_STATE', custome: 'tag', type: 'success', label: '健康状态' },
			{ prop: 'workTypeLabel', code: 'WORK_TYPE', custome: 'tag', type: 'success', label: '工作类型' },
			{ prop: 'serviceStateLabel', code: 'SERVICE_STATE', custome: 'tag', type: 'success', label: '服务状态' },
			{ prop: 'organizationName', type: 'success', label: '所在单位' },
		]
	},
}
const model = ref({
	year: '',
	month: '',
})
const drawer = ref(false)
const baseModel: any = shallowRef({})
const loading = ref(false)
const modelData: any = ref({})
const orgArchivesEl = ref(null)
let moreNewsModel: any = ref({})

const tableColumnConfig = (data?: any) => {
	return [
		[
			{ m: '姓名',style:{width:'180px'} },
			{
				m: '',
				style:{width:'180px'},
				prop: 'staffName',
				archives: true,
				archivesText: '档案',
				showLink: (col, model) => {
					staffInfoShow.value = true
				},
			},
			{ m: '性别' },
			{
				m: '',
				setColor: true,
				style: { width: '180px' },
				prop: 'genderLabel',
			},
			{ m: '出生日期',style:{width:'180px'} },
			{
				m: '',
				setColor: true,
				style:{width:'180px'},
				prop: 'birthday',
			},
			{ m: '民族',style: { width: '180px' }  },
			{
				m: '',
				style: { width: '180px' },
				setColor: true,
				prop: 'nationalLabel',
			},
			{
				m: '照片',
				style:{width:'100px'},
				prop: 'staffPhoto',
				mc: {
					rs: 4,
					cs: 1,
				},
			},
		],

		[
			{ m: '身份证号' },
			{
				m: '',
				prop: 'idCard',
				setColor: true,
				mc: {
					rs: 1,
					cs: 3,
				},
			},
			{ m: '文化程度' },
			{
				m: '',
				prop: 'cultureDegreeLabel',
				setColor: true,
			},
			{ m: '联系电话' },
			{
				m: '',
				prop: 'phone',
				setColor: true,
			},
		],
		[
			{ m: '参加护理工作时间' },
			{
				setColor: true,
				m: '',
				prop: 'nurseTime',
				mc: {
					rs: 1,
					cs: 3,
				},
			},
			{
				m: '毕业院校',
			},
			{
				setColor: true,
				m: '',
				prop: 'graduationInstitution',
				mc: {
					rs: 1,
					cs: 3,
				},
			},
		],
		[
			{
				m: '申领学历(全日制)',
			},
			{
				setColor: true,
				m: '',
				prop: 'educationalQualificationsFullTime',
				mc: {
					rs: 1,
					cs: 3,
				},
			},
			{
				m: '申领学历(非全日制)',
			},
			{
				setColor: true,
				m: '',
				prop: 'educationalQualificationsPartTime',
				mc: {
					rs: 1,
					cs: 3,
				},
			},
		],
		[
			{ m: '资格证书名称' },
			{ m: '', prop: 'qualificationCertificateName', mc: { rs: 1, cs: 2 } },
			{ m: '编号', style: { width: '180px' } },
			{ m: '', prop: 'qualificationCertificateCode' },
			{ m: '已领奖励金额及已领取年限', style: { width: '180px' }, mc: { rs: 1, cs: 3 } },
			{ 
				m: '', 
				prop: 'moneyAndYear',
				// archives: true,
				// archivesText: '详',
				// showLink: (col, model) => {
				// 	orgArchivesEl.value?.getServiceOrgInfo(model.creditCode)
				// }
			},
		],
		[
			{ m: '资格证书名称' },
			{ m: '', prop: 'qualificationCertificateName1', mc: { rs: 1, cs: 2 } },
			{ m: '编号', style: { width: '180px' } },
			{ m: '', prop: 'qualificationCertificateCode1' },
			{ m: '申请领取奖励金额及申请领取年度', style: { width: '180px' }, mc: { rs: 1, cs: 3 } },
			{ 
				m: '',
				prop: 'applyMoneyAndYear',
				// archives: true,
				// archivesText: '详',
				// showLink: (col, model) => {
				// 	orgArchivesEl.value?.getServiceOrgInfo(model.creditCode)
				// }
			},
		],
		[
			{
				m: '用人单位名称',
			},
			{
				m: '',
				prop: 'organizationName',
				mc: { rs: 1, cs: 3 },
				archives: true,
				archivesText: '档案',
				showLink: (col, model) => {
					orgArchivesEl.value?.getServiceOrgInfo(model.creditCode)
				},
			},
			{
				m: '地址',
			},
			{ m: '', prop: 'organizationAddress', mc: { rs: 1, cs: 4 } },
		],

		[
			{
				m: '用人单位意见',
			},
			{
				m: '',
				prop: 'note',
				mc: {
					rs: 1,
					cs: 8,
				},
			},
		],
    [
			{
				m: '街（镇）民政部门意见',
			},
			{
				m: '',
				prop: 'noteS',
				mc: {
					rs: 1,
					cs: 8,
				},
			},
		],
     [
			{
				m: '第三方核查意见',
			},
			{
				m: '',
				prop: 'noteT',
				mc: {
					rs: 1,
					cs: 8,
				},
			},
		],
		[
			{
				m: '审批意见',
			},
			{
				m: '',
				prop: 'note2',
				mc: {
					rs: 1,
					cs: 8,
				},
			},
		],
	]
}
const dataList = ref(tableColumnConfig())

const editMoneyAndYear = () => {
	let query = {
		id: props.editData.result_case_id,
		dataContent: modelData.value,
		dataResults: modelData.value,
		fromId: props.editData.formId,
		fromType: 'area_staff_entry_report',
		tableTemplateId: 'area_staff_entry_report',
		projectId: props.params.subsidyProjectId,
	}
	apiMod.view_formResults_edit(query).then((res) => {
		ElMessage.success('修改成功')
	})
}

const getInitData = async () => {
	const params = props.params || {}
	
	// if (params.belongDate) {
	// 	query.year = params.belongDate.replace('年', '-').replace('月', '').split('-')[0]
	// 	query.month = params.belongDate.replace('年', '-').replace('月', '').split('-')[1]
	// 	model.value.year = query.year
	// 	model.value.month = query.month
	// } else {
	// 	return
	// }
	if ((props.approvalStatus == 1 || !props.approvalStatus)&&!props.isPigeonhole) {
		
		try {
			let date = props.params.belongDate.split('-')
			const query = {
				year: date[0],
				month: date[1],
				creditCode: params.organizationId || props.otherData.creditCode,
				idCard: params.applicateObject || props.otherData.staffIdCard,
				// projectId: props.params.subsidyProjectId,
			}
			
			loading.value = true
			const uptoData = await apiMod.view_subsidy_onBoarding(query).then((res) => res.data)
			bus.emit('entryListData',uptoData)
			
			// 获取list
			uptoData.moneyAndYear = props.editData.moneyAndYear
			uptoData.applyMoneyAndYear = props.editData.applyMoneyAndYear
			loading.value = false
			const resultData =  uptoData
			baseModel.value = JSON.parse(JSON.stringify(resultData))
			const reportData = filterEmptyObj(resultData)
			if (uptoData.dataContent) {
				moreNewsModel.value = {
					...uptoData.dataContent,
					viewStatus: uptoData?.viewStatus || '',
				}
			} else {
				moreNewsModel.value = {
					viewStatus: uptoData?.viewStatus|| '',
				}
			}
			
			modelData.value = uptoData
			// 判断本科及以上，全日制
			if(uptoData.educationalQualificationsFullTime&&(uptoData.educationalQualificationsFullTime=='研究生'||uptoData.educationalQualificationsFullTime=='研究生以上'||uptoData.educationalQualificationsFullTime=='全日制本科')){
				modelData.value.amass = 50000
			}else if(uptoData.educationalQualificationsFullTime&&(uptoData.educationalQualificationsFullTime=='全日制大专')){
				modelData.value.amass = 40000
			}else if(uptoData.educationalQualificationsFullTime&&(uptoData.educationalQualificationsFullTime=='中专')){
				modelData.value.amass = 30000
			}
			// 非全日制
			if(uptoData.educationalQualificationsPartTime&&(uptoData.educationalQualificationsPartTime=='非全日制本科')){
				modelData.value.amass = 50000*0.7
			}else if(uptoData.educationalQualificationsPartTime&&(uptoData.educationalQualificationsPartTime=='非全日制大专')){
				modelData.value.amass = 40000*0.7
			}else if(uptoData.educationalQualificationsPartTime&&(uptoData.educationalQualificationsPartTime=='非全日制中专')){
				modelData.value.amass = 30000*0.7
			}
			
			dataList.value = tableColumnConfig(reportData)
			// 没审批或没提交时保存
			handleSave()
		} catch (error) {
			loading.value = false
		}
	} else if(props.isPigeonhole){
		modelData.value = props.editData
	} else if(props.editData.result_case_id) {
	
		modelData.value = props.editData
	}
	bus.emit('waitSubmitEntryListData',modelData.value)
	modelData.value.practitionersName = modelData.value.staffName
}
onMounted(() => {
	if (props.params) getInitData()
})

const handleSave = () => {
	emit('save', modelData.value, 'area_staff_entry_report', props.editData)
}

onUnmounted(() => {})
</script>

<style scoped lang="scss">
.text-underline {
	text-decoration: underline;
	padding: 0 6px;
}
.report-table-wrapper {
	width: 100%;
	margin: 0 auto;
	padding: 10px 30px;
	top: 0;

	.t-header {
		text-align: center;
		font-size: 18px;
		font-weight: bold;
		padding: 15px 0;

		.text-sm {
			font-weight: 400;
			font-size: 16px;
		}
	}
}

.article-title {
	position: relative;
	z-index: 0;
	width: 63%;
	margin: 0 auto;
}

.text-tip {
	--base-text-bg: rgb(56 176 255 / 13%);
	position: absolute;
	width: 100%;
	height: 100%;
	background: var(--base-text-bg);
	padding: 4px;
	z-index: -1;
	&:hover {
		cursor: pointer;
	}
	.tip-text-new {
		position: absolute;
		right: 0;
		top: -10px;
		color: #fff;
		border-radius: 4px;
		padding: 2px;
		width: 40px;
		background-color: #ed6d05;
	}
	.tip-text-detail {
		background-color: #179fe3;
		position: absolute;
		right: 0;
		top: -10px;
		color: #fff;
		border-radius: 4px;
		padding: 2px;
		width: 40px;
	}
}
</style>
